package com.xw.controller.api;

import com.google.common.collect.Maps;
import com.xw.common.Const;
import com.xw.service.UserConcernService;
import com.xw.util.AppUtil;
import com.xw.util.JsonData;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @需求描述: 用户关注
 * @创建人:whh
 * @创建时间: 2019/11/11
 * @修改需求:
 * @修改人:
 * @修改时间:
 * @需求思路:
 */
@Controller
@RequestMapping("/api/userConcern/")
@Scope("prototype")
public class ApiUserConcernController {

    @Resource
    private UserConcernService userConcernService;

    /**
     * 关注讲师 - 小程序
     * @param userId
     * @param teacherId
     * @return
     */
    @RequestMapping(value = "focusTeacherMP",method = RequestMethod.POST)
    @ResponseBody
    public Object focusTeacherMP(String userId,String teacherId){
        //判断传参
        Map map = Maps.newHashMap();
        map.put("userId", userId);
        map.put("teacherId", teacherId);
        String str = AppUtil.checkIsNull(map);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        map.clear();
        map = userConcernService.focusTeacherMP(userId,teacherId);
        return map;
    }

    /**
     * 取消关注讲师 - 小程序
     * @param userId
     * @param teacherId
     * @return
     */
    @RequestMapping(value = "cancelFocusTeacherMP",method = RequestMethod.POST)
    @ResponseBody
    public Object cancelFocusTeacherMP(String userId,String teacherId){
        //判断传参
        Map map = Maps.newHashMap();
        map.put("userId", userId);
        map.put("teacherId", teacherId);
        String str = AppUtil.checkIsNull(map);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        map.clear();
        map = userConcernService.cancelFocusTeacherMP(userId,teacherId);
        return map;
    }

    /**
     * 名师推荐-我的关注 -小程序
     * @param userId
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping(value = "findFocusTeacherByUserId",method = RequestMethod.POST)
    @ResponseBody
    public Object findFocusTeacherByUserId(String userId,Integer page,Integer limit){
        //判断传参
        Map map = Maps.newHashMap();
        map.put("userId", userId);
        String str = AppUtil.checkIsNull(map);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        map.clear();
        map = userConcernService.findFocusTeacherByUserId(userId,page,limit);
        return map;
    }

    /**
     * 我的 - 我的粉丝 - 小程序
     * 我的粉丝里边包括导师和普通用户，对导师可以进行关注或者取消关注，对普通用户没有任何操作，点击导师可以进入导师详情页
     * @param userId
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping(value = "findMyFansByUserId",method = RequestMethod.POST)
    @ResponseBody
    public Object findMyFansByUserId(String userId,Integer page,Integer limit){
        //判断传参
        Map map = Maps.newHashMap();
        map.put("userId", userId);
        String str = AppUtil.checkIsNull(map);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        map.clear();
        map = userConcernService.findMyFansByUserId(userId,page,limit);
        return map;
    }

}
